import React, {useState,useRef} from 'react';
import { View,TouchableNativeFeedback,Alert} from 'react-native'
import ViewShot from "react-native-view-shot";
// import QRCode from 'react-native-qrcode-svg';
import {SaveImg} from '@/utils/selectImg'
import {pTx} from '@/utils/size';
import Language from '@/language/Language'
let QRCodeScreen = (props:any)=>{
    const saveQRCode = useRef<any>();

    function onSaveQRCode(){
        saveQRCode.current.capture().then(url => {
            SaveImg(url,{type:'photo'}).then(()=>{
                Alert.alert('二维码保存成功！');
            }).catch(err=>{
                Alert.alert('图片保存失败！');
            })
        }).catch(error=>{
            Alert.alert('生成图片失败！');
        });
    }

    return (
        <ViewShot ref={saveQRCode} options={{ fileName: "Your-File-Name", format: "png", quality:1 }} style={{flex:1,flexDirection:'column',alignItems:'center',justifyContent:'center'}}>
            <TouchableNativeFeedback onLongPress={()=>onSaveQRCode()}>
                <View style={{padding:pTx(20),backgroundColor:'#fff',borderRadius:pTx(4)}}>
                    {/* <QRCode
                        value={props.value}
                        size={props.size||pTx(20)}
                    /> */}
                </View>
            </TouchableNativeFeedback>
        </ViewShot>
    )
}

export default QRCodeScreen;